package com.agile.leetcode.node.treversenode;

/**
 * @Author KD
 * @Date 2021/1/6 13:51
 */
public class TraverseNode {
    public static void main(String[] args) {

    }

    public Node traverseNode(Node root) {
        if (root == null) {
            return null;
        }
        Node current = root;
        Node newNode = null;
        Node pre = null;
        while (current != null) {
            Node next = current.next;
            if (next == null) {
                newNode = current;
            }
            current.next = pre;
            pre = current;
            current = next;
        }
        return newNode;
    }
}

class Node {
    int value;
    Node next;
}
